<template>
  <div class="goods-hot">
    <h3>{{ title }}</h3>
    <div>
      <GoodsItem v-for="item in list" :key="item.id" :goods="item" />
    </div>
  </div>
</template>
<script>
import { computed, ref } from 'vue'
// import { useRoute } from 'vue-router'
import GoodsItem from '@/views/category/components/goods-item.vue'
import { goodsHot } from '@/api/product'
export default {
  name: 'GoodsHot',
  components: {
    GoodsItem
  },
  props: {
    type: {
      type: Number,
      default: 1
    },
    id: {
      type: String
    }
  },
  setup (props) {
    // const route = useRoute()
    const titleObj = { 1: '24小时热销榜', 2: '周热销榜', 3: '总热销榜' }
    const title = computed(() => {
      return titleObj[props.type]
    })
    // 获取数据
    const list = ref([])
    goodsHot({
      id: props.id,
      limit: 3,
      type: props.type
    }).then(res => {
      // console.log('热销 数据', res)
      list.value = res.result
    })

    return { title, list }
  }
}
</script>
<style scoped lang="less"></style>
